package indi.zhifa.study2024.nbr.busycore.logic.report.define.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import freemarker.template.utility.StringUtil;
import indi.zhifa.study2024.nbr.busycore.gen.busy.define.po.GenItemEntity;
import indi.zhifa.study2024.nbr.busycore.gen.busy.define.service.IGenItemDbService;
import indi.zhifa.study2024.nbr.busycore.logic.report.define.IItemService;
import indi.zhifa.study2024.nbr.busycore.logic.report.define.entity.ItemPageRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@RequiredArgsConstructor
@Slf4j
@Component
public class ItemServiceImpl implements IItemService {

    private final IGenItemDbService mItemDbService;

    @Override
    public Page<GenItemEntity> page(ItemPageRequest pItemPageRequest) {

        LambdaQueryWrapper<GenItemEntity> queryWrapper = Wrappers.<GenItemEntity>lambdaQuery()
                .like(StringUtils.hasText(pItemPageRequest.getName()),GenItemEntity::getName, pItemPageRequest.getName());
        Page<GenItemEntity> pageCfg = new Page<>(pItemPageRequest.getSize(),pItemPageRequest.getSize());

        return mItemDbService.page(pageCfg,queryWrapper);
    }
}
